package com.zcx.qshop.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/28.
 */
@HttpInlet(Conn.INLET_JSON_ACOUNT)
public class JsonAcountAsyGet extends QSAsyGet<JsonAcountAsyGet.Info> {

    public String userid;

    public JsonAcountAsyGet(String userid, AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

        this.userid = userid;

    }

    @Override
    protected Info parser(JSONObject object) {

        if(object.optString("message").equals("1")){

            Info info = new Info();

            info.acount = object.optString("acount");

            JSONArray array = object.optJSONArray("acountlist");

            if(array != null){

                for (int i = 0 ; i < array.length() ; i ++){

                    JSONObject o = array.optJSONObject(i);

                    Acount acount = new Acount();

                    acount.flowacount = o.optString("flowacount");

                    acount.posttime = o.optString("posttime");

                    acount.info = o.optString("info");

                    info.acounts.add(acount);

                }

            }

            return info;

        }

        return null;

    }

    public static class Info{

        public String acount;

        public List<Acount> acounts = new ArrayList<>();

    }

    public static class Acount{

        public String flowacount, posttime, info;

    }

}
